package com.tentact.coolmeetingtest.controller.servlet;

import com.tentact.coolmeetingtest.annotation.RequestParam;
import com.tentact.coolmeetingtest.service.RoomService;
import com.tentact.coolmeetingtest.support.MyMessage;
import com.tentact.coolmeetingtest.support.RetMsg;
import com.tentact.coolmeetingtest.vo.Room;
import jakarta.servlet.ServletException;

import java.io.IOException;
import java.util.List;

/**
 * @author 星环
 * @date 2023/1/30 9:50:05
 * @description
 */
public class RoomServlet {
    RoomService roomService = new RoomService();
    public MyMessage addRoom(Room room) throws ServletException, IOException {
        System.out.println(room);
        roomService.addRoom(room);
        return MyMessage.of(false,"addmeetingroom.jsp");
    }

    public MyMessage showAll() throws ServletException, IOException {
        List<Room> roomList = roomService.getAll();
        return MyMessage.of(false,"showmeetingrooms.jsp","rooms",roomList);
    }

    public MyMessage showDetail(@RequestParam("roomno") int roomno){
        Room room = roomService.getDetailByRoomno(roomno);
        return MyMessage.of(false,"showdetail.jsp","room",room);
    }

    public MyMessage changeRoom(Room room) throws ServletException, IOException {
        System.out.println(room);
        RetMsg retMsg = roomService.changeRoomById(room);
        return MyMessage.of(true,"room.showAll","msg",retMsg.msg);
    }
}
